package ee.helmesWorkTest.backend.initialData;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

import ee.helmesWorkTest.backend.database.ConnectionManager;
import ee.helmesWorkTest.backend.model.dao.SectorDAO;
import ee.helmesWorkTest.backend.model.dao.factory.DAOFactory;
import ee.helmesWorkTest.backend.model.data.Sector;
import ee.helmesWorkTest.utils.SectorDataFinder;

public class PersistInitialDataToDatabase 
{
	/*
	Logger logger = Logger.getLogger(PersistInitialDataToDatabase.class);

	private static DAOFactory daoFactory = DAOFactory.getDAOFactory();
	private static SectorDAO sectorDAOImpl;
	
	public static void main(String[] args) throws SQLException 
	{
		PersistInitialDataToDatabase persistInitialDataToDatabase = new PersistInitialDataToDatabase();
		persistInitialDataToDatabase.insertSectors();
	}
	
	public static void insertSectors() throws SQLException 
	{
		Connection dbConnection = ConnectionManager.getInstance().getConnection();
		dbConnection.setAutoCommit(false);
		sectorDAOImpl = daoFactory.getSectorDAOImpl(dbConnection);
		
		try 
		{
			SectorDataFinder sectorDataFinder = new SectorDataFinder();
			List<SectorData> listWithSectorHierarchy = sectorDataFinder.getSectorDataList();
			for (SectorData sectorData : listWithSectorHierarchy)
			{
				Sector sector = new Sector();
				sector.setSectorID(sectorData.getSectorID());
				sector.setSectorName(sectorData.getSectorName());
				if (sectorData.getParentGeneralSector() != null
						&& sectorData.getParentGeneralSector().getSectorID() != null)
				{
					sector.setParentGeneralSector(sectorData.getParentGeneralSector().getSectorID());
				}
				sector.setLevelInHierarchy(sectorData.getLevelInHierarchy());
				
				sectorDAOImpl.insertSectorInitialData(sector);
			}
			
			dbConnection.commit();
				
		}
		catch (Exception e) 
		{
			dbConnection.rollback();
			e.printStackTrace();
		}
		finally
		{
			ConnectionManager.getInstance().closeConnection();
		}
	}
	*/
}
